<template>
  <div>
    <div class="product-left">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="产品图片" prop="name">
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="" />
          </el-dialog>
        </el-form-item>
        <el-form-item label="状态" prop="resource">
          <el-radio-group v-model="ruleForm.resource">
            <el-radio label="上架"></el-radio>
            <el-radio label="下架"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="产品分类" prop="region">
          <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品分组" prop="region">
          <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品买点" prop="desc">
          <el-input type="textarea" v-model="ruleForm.desc"></el-input>
        </el-form-item>
        <el-form-item label="配送方式" prop="type">
          <el-checkbox-group
            v-model="ruleForm.type"
            @change="handleCheckChange"
          >
            <el-checkbox label="商家配送" name="type"></el-checkbox>
            <el-checkbox label="用户自提" name="type"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item v-if="isFormVisible" label="运费设置" prop="region">
          <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品规格">
          <el-button size="mini" @click="addGuige">添加规格</el-button>
        </el-form-item>
        <div v-if="(showGuige = false)">
          <el-form-item label="规格名">
            <el-select v-model="ruleForm.region" placeholder="请选择">
              <el-option label="内存" value="shanghai"></el-option>
              <el-option label="颜色" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="规格值">
            <el-select v-model="ruleForm.region" placeholder="请选择">
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              size="mini"
              type="primary"
              @click="submitForm('ruleForm')"
              >确定</el-button
            >
            <el-button size="mini" @click="cancelGuige">取消</el-button>
          </el-form-item>
        </div>
        <!-- 表格 -->
        <el-form-item label="产品详情">
          <quill-editor
            ref="textEditor"
            v-model="articleContent"
            :options="editorOption"
          >
          </quill-editor>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { quillEditor } from "vue-quill-editor";
// import { ProdSelet } from "@/components/prod-select";
// import { Debounce } from "@/utils/debounce";
// import { encrypt } from "@/utils/crypto";
export default {
    components: {
    quillEditor,
  },
  data() {
    return {
      ruleForm: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      isFormVisible: false,
      showGuige: false,
      // 规格
      specs: [],

      rules: {
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],

        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
      },
      // 富文本
      editorOption: {
        modules: {
          toolbar: [
            ["bold", "italic", "underline", "strike"],
            ["blockquote"],
            [{ list: "ordered" }, { list: "bullet" }],
            [{ script: "sub" }, { script: "super" }],
            [{ indent: "-1" }, { indent: "+1" }],
            [{ size: ["small", false, "large", "huge"] }],
            [{ color: [] }, { background: [] }],
            ["clean"],
            [{ align: [] }, "image"],
          ],
        },
        placeholder: "请输入文章内容 ...",
      },
      articleTitle: "",
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 规格
    addGuige() {
      this.showGuige = true;
    },
    cancelGuige() {
      this.showGuige = false;
      this.resetForm(); // 如果需要重置表单
    },
    //   配送方式显示
    handleCheckChange(value) {
      this.isFormVisible = value.includes("商家配送");
    },
    // 获取数据列表
    getDataList(page, params, done) {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/prod/prod/info/" + id),
        method: "get",
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize,
            },
            params
          )
        ),
      }).then(({ data }) => {
        this.dataList = data.records;
        this.page.total = data.total;
        this.dataListLoading = false;
        if (done) {
          done();
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>